package devcken.text;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

public class Encoding
{
	public static Encoding Default = new Encoding(Charset.defaultCharset().name());
	public static Encoding ASCII = new Encoding("ascii");
	public static Encoding UTF8 = new Encoding("utf-8");
	
	private String _charset = "utf-8";
	
	private Encoding(String charset)
	{
		this._charset = charset;
	}
	
	public String getString(byte[] binary, int offset, int length)
	{
		try
		{
			return new String(binary, offset, length, this._charset);
		}
		catch (UnsupportedEncodingException error)
		{
			return null;
		}
	}
}